package cn.wolfcode.wolf2w.business.listen;

import cn.wolfcode.wolf2w.api.domain.UserInfoSearch;
import cn.wolfcode.wolf2w.business.repository.UserInfoRepository;
import cn.wolfcode.wolf2w.member.api.domain.UserInfo;
import com.alibaba.fastjson.JSON;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @author 浪兎兎
 * @since 2025-06-16 13:38
 */
@Component
public class UserInfoListener {
    @Autowired
    private UserInfoRepository userInfoRepository;
    @RabbitListener(queues = {"userInfoQueue"})
    public void onMessage(String message) {
        UserInfo userInfo = JSON.parseObject(message, UserInfo.class);
        UserInfoSearch userInfoSearch = new UserInfoSearch();
        BeanUtils.copyProperties(userInfo, userInfoSearch);
        userInfoRepository.save(userInfoSearch);
    }
}
